package dyyx.util;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

public abstract class MetricsUtil {
	
	private static final String[] countKeys = {"gcInvoke"};
	private static final String[] timeKeys = {"compile","compile_step1","compile_step2"};
	

	
	public static String getMetrics(){
		StringBuilder sb = new StringBuilder();
		sb.append("droolsdemo_nowtime ").append(System.currentTimeMillis()).append("\n");
		
		for(String key:countKeys){
			AtomicLong al = RunStatusUtil.runStatus.countMap.get(key);
			if(al==null){
				continue;
			}
			sb.append(key+" ").append(al.get()).append("\n");
		}
		for(String key:timeKeys){
			TimeInfo ti = RunStatusUtil.runStatus.timeInfoMap.get(key);
			if(ti==null){
				continue;
			}
			sb.append(key+"_total ").append(ti.sum.get()).append("\n");
			sb.append(key+"_count ").append(ti.count.get()).append("\n");

		}
		//sb.append("total_pv ").append(PVUtil.getpv()).append("\n");
		//Map<String,Long> pvs = PagePVUtil.getpv();
		//Set<Map.Entry<String,Long>> kvs = pvs.entrySet();
		// xxx{a="x",b="y"}
		
		/*
		for(Map.Entry<String,Long> item:kvs){
			sb.append("page_pv{page=\"").append(item.getKey()).append("\"} ").append(item.getValue()).append("\n");
		}
		*/
		
		try {
			MetricItems items = JvmStatusUtil.getMetrics();
			List<MetricItem> list = items.getAll();
			for (MetricItem item : list) {
				// System.out.println(item.toString());
				sb.append(item.toString()).append("\n");
			}
		} catch (Throwable e) {
			//
		}
		 
		
		
		
		sb.append("\n");
		return sb.toString();
	}

	

}